package leetcode.primary;

import utils.linkedList.ListNode;

import java.util.HashSet;
import java.util.Set;

public class T141 {
    public boolean hasCycle(ListNode head) {
        if (head==null||head.next==null){
            return false;
        }
        ListNode node1 = head;
        ListNode node2;
        int count;
        final int MAX = (int) Math.pow(10,4);
        while (node1!=null){
            if (node1.next!=null){
                node2 = node1.next.next;
            }else {
                node2 = null;
            }
            count = 0;
            //开始遍历
            while (node2!=null && node2!=node1.next&& count<=MAX){
                node2 = node2.next;
                count++;
            }
            if (node2==null){
                return false;
            }
            node1 = node1.next;
        }
        return false;
    }

    public static void main(String[] args) {

    }
}
